package yangtuo.io.web;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import yangtuo.io.core.restful.Result;
import yangtuo.io.core.restful.ResultGenerator;
import yangtuo.io.dal.AlpacaTest;
import yangtuo.io.service.alpaca.IAlpacaService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <pre>
 *   sprint boot controller test
 * </pre>
 * Created by sirius on 2018/9/19.
 *
 * @author sirius
 * @since 1.0
 */
@Controller
@RequestMapping(value = "alpaca")
public class AlpacaController {

    @Autowired
    private IAlpacaService alpacaService;

    @ResponseBody
    @RequestMapping(value = "getAll", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public PageInfo getAll(HttpServletRequest request, HttpServletResponse response) {
        List<AlpacaTest> resultList = alpacaService.getAllAlpaca(2, 8);
        return new PageInfo(resultList);
    }

    @ResponseBody
    @RequestMapping(value = "saveAlpaca", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public Result saveAlpaca(HttpServletRequest request, HttpServletResponse response) throws Exception {
        alpacaService.saveAlpaca("sirius");
        return ResultGenerator.genSuccessResult();
    }


}
